package batchcal.mas.dtc.scripts.outsource.source.impl;

import batchcal.mas.dtc.scripts.outsource.source.IDataSource;
import batchcal.mas.dtc.util.baidu.HotelSOAUtil;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: ycy
 * @CreateDate: 2018/8/27 15:18
 */
public class HttpDataSource implements IDataSource {

  /**
   * 日志
   */
  protected static final Logger LOG = LoggerFactory.getLogger(HttpDataSource.class);

  /**
   * 返回一个实例
   * @return 实例
   */
  public static HttpDataSource getInstance(){
    return new HttpDataSource();
  }

  @Override
  public boolean checkCommand(String type) {
    return true;
  }

  @Override
  public Map<String, Object> getDataFromDataSource(Map<String, Object> ids, String type) {
    Map<String,Object> result = new HashMap<String,Object>();
    Object cityid = ids.get("cityid");

    String resStr = HotelSOAUtil.getRes(Integer.parseInt(String.valueOf(cityid)));
    int sum = 0;
    if (resStr != null){
     Object  object =  JSONObject.parse(resStr);
     Map<String,Object> map = (Map)object;
     List list = (List) map.get("recommendArticleInfoList");
    sum = list.size();
    }
    if(sum<=0){
      result.put("is",sum);
    }else{
      result.put("is",sum);
    }
    return result;
  }

  @Override
  public boolean setDataSourceField(String sourceMetaStr) {
    return true;
  }
}
